package com.nosweattechnet.server;

import java.util.concurrent.ExecutionException;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;

public class AddItemLocationAsyncTask extends CommunicatorAsyncTask {
	private final BasicNameValuePair tag=new BasicNameValuePair("tag","addItemLocation");
	private final String itemIDString="item_uuid";
	private final String locXString="loc_x";
	private final String locYString="loc_y";
	private final String locZString="loc_z";
	private final String weightString="weight";
	private final Float defaultWeight=(float) 1.0;
	private final Float defaultloc_z=(float) 1.0;
	
	//Creates a new Async task and adds the associated values to the name value pairs
	public AddItemLocationAsyncTask(String item_id,Float loc_x,Float loc_y){
		super();
		super.addNameValuePair(tag);
		super.addNameValuePair(new BasicNameValuePair(itemIDString,item_id));
		super.addNameValuePair(new BasicNameValuePair(locXString,loc_x.toString()));
		super.addNameValuePair(new BasicNameValuePair(locYString,loc_y.toString()));
		super.addNameValuePair(new BasicNameValuePair(locZString,defaultloc_z.toString()));
		super.addNameValuePair(new BasicNameValuePair(weightString,defaultWeight.toString()));
	}
	
	//Checks if the Item Location was added
	public boolean addedLocation() throws InterruptedException, ExecutionException{
		try {
			JSONArray jarray = this.get();
			if(jarray==null){
				return false;
			}
			if(jarray.getBoolean(0)){
				return true;
			}
		} catch (JSONException e) {
			return false;
		}
		return false;
	}
}
